<?php

class ApaPostValidatorBase extends sfValidatorSchema
{
    protected static $name;

    protected static function buildClassName($format)
    {
        $class = get_called_class();
        $className = sprintf($format, ucfirst($class::$name));

        return $className;
    }

    /**
     * Daca au fost specificate pierderi, trebuie ca si modul de distribuire a lor sa fie selectat.
     *
     * @param type $values
     * @return type
     */
    protected function doClean($values)
    {
        $errorSchema = new sfValidatorErrorSchema($this);

        $className = self::buildClassName('CriteriuFormApa%s');
        if ($values[$className::PIERDERI] && !$values[$className::REPARTIZARE_PIERDERI])
        {
            $error = new sfValidatorError($this, 'required');
            $errorSchema->addError($error, $className::REPARTIZARE_PIERDERI);

            throw $errorSchema;
        }

        // daca pierderile nu sunt specificate, nu are rost sa pastrez modul de repartizare a lor
        if (!$values[$className::PIERDERI])
        {
            unset($values[$className::REPARTIZARE_PIERDERI]);
        }

        return $values;
    }
}
